//
//  BSAddFairViewController.m
//  BaiSiBuDeJie
//
//  Created by 王位 on 9/2/16.
//  Copyright © 2016 tsaievan. All rights reserved.
//

#import "BSAddFairViewController.h"

#import "UIView+HM.h"

#import "WWImage.h"

@interface BSAddFairViewController ()

@property(nonatomic,strong)UIImageView * imageView;

@end

@implementation BSAddFairViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIImageView * backGroundImageView = [[UIImageView alloc]initWithFrame:self.view.bounds];
    
    backGroundImageView.image = [UIImage imageNamed:@"b717b04c899e"];
    
    [self.view addSubview:backGroundImageView];
    
    self.navigationItem.title = @"裁剪";
    
    
    [self addFairView];
    
    [self addHeadView];
}

//添加头View
-(void)addHeadView
{
    UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.w, 44)];
    
    UIButton * btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, view.h, view.h)];
    
    view.backgroundColor = [UIColor whiteColor];
    
    [btn setImage:[UIImage imageNamed:@"IMG_0672"] forState:UIControlStateNormal];
    
    [btn addTarget:self action:@selector(didClicCancel) forControlEvents:UIControlEventTouchDown];
    
    [view addSubview:btn];
    
    [self.view addSubview:view];
}

-(void)didClicCancel
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

-(void)addFairView
{
    UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0,self.view.h - 200, self.view.w, 200)];
    
    view.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:view];
    
}


-(void)setPictureImage:(UIImage *)pictureImage
{
    _pictureImage = pictureImage;
    
    
    
    self.imageView = [[UIImageView alloc]initWithImage:_pictureImage];
    
    self.imageView.contentMode = UIViewContentModeScaleAspectFill;
    
    self.imageView.clipsToBounds = YES;
    
    self.imageView.frame = CGRectMake(0, 44 * 2, self.view.w, self.view.w);
    
    
    
    
    
    self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, M_PI_2);
    
    [self.view addSubview:self.imageView];
    
    //存入相册
    
    UIImageWriteToSavedPhotosAlbum(self.pictureImage, nil, nil, nil);
    
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(BOOL)prefersStatusBarHidden
{
    return  YES;
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
